from flask import jsonify, request


class ResponseCode(object):
    SUCCESS = 2000

    REQUEST_ERROR = 4000
    PARAMETER_ERROR = 4001
    TOKEN_INVALID = 4002
    FORBIDDEN_REQUEST = 4003
    RESOURCE_NOT_FOUND = 4004
    PERMISSION_DENIED = 4005
    OPERATOR_ERROR = 4006  # 操作错误

    INTERNAL_SERVER_ERROR = 5000


def success_json(data=None, **kwargs):
    return jsonify({'errcode': ResponseCode.SUCCESS, 'data': data or {}, **kwargs})


def error_json(errcode, errmsg, data=None):
    return jsonify(
        {'errcode': errcode,
         'errmsg': errmsg,
         'method': request.method,
         'url': request.url,
         'data': data or {}}
    )